import { _decorator, Component, Node, Sprite } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('bg')
export class bg extends Component {
	@property(Node) public bg01: Node;
	@property(Node) public bg02: Node;

	private speed: number = 300;

	update(deltaTime: number) {
		const bgHeight = 852;
		const pos1 = this.bg01.position;
		const pos2 = this.bg02.position;

		this.bg01.setPosition(0, pos1.y - this.speed * deltaTime);
		this.bg02.setPosition(0, pos2.y - this.speed * deltaTime);

		if (pos1.y <= -bgHeight) {
			this.bg01.setPosition(0, pos2.y + bgHeight);
		} else if (pos2.y <= -bgHeight) {
			this.bg02.setPosition(0, pos1.y + bgHeight);
		}
	}
}
